# -*- coding:utf-8 -*-
# 日期：2021年12月24日


from flask import Flask, request, render_template, url_for, redirect, flash
user_name = ["Xinxin"]
user_pwd = ["hhh233"]


app = Flask(__name__)
app.secret_key = 'dklfsghls;d/'


@app.route('/')
def index():
    return render_template('index.html')



@app.route('/shop')
def shop():
    return render_template('shop.html')


@app.route('/login', methods=['POST', 'GET'])
# 登录界面
def login():
    return render_template('login.html')

#购物车界面
@app.route("/shop", methods=['POST','GET'])
def shopping():
    return render_template('shop.html')


#支付成功界面
@app.route('/success',methods=['POST','GET'])
def success():
    return render_template('success.html')





#名字全称
@app.route('/name', methods=['POST', 'GET'])
def fullname():
    return render_template("fullname.html")


@app.route('/fullname', methods=['POST', 'GET'])
def result_name():
    firstname = request.form.get("firstname")
    lastname = request.form.get("lastname")
    full_name = firstname.title() + ' ' + lastname.title()
    return render_template("result_name.html", name=full_name)

#词频统计
@app.route('/word', methods=['POST', 'GET'])
def searchs():
    return render_template("search.html")


@app.route('/words', methods=['POST', 'GET'])
def result_word():
    word = request.form.get("word")
    vowels = request.form.get("vowels")
    found = {}
    for i in word:
        if i in vowels:
            found.setdefault(i, 0)
            found[i] += 1
    for j in found:
        k = j
        v = found[j]

    return render_template("result_words.html",
                           key=k,
                           value=v
                           )





if __name__ == '__main__':
    app.run(host='127.0.0.1', port=5000, debug=True)



@app.errorhandler(404)
# 404
def page_not_fount(error):
    return render_template('404.html'), 404


@app.errorhandler(500)
# 500
def internal_server_error(error):
    return 'Datebase connection failed', 500


if __name__ == '__main__':
    app.run(debug=True)
